<!DOCTYPE html>
<html>
<head>
    

    

    



    <meta charset="utf-8">
    
    
    
    <title>2.1.6 Consul高可用 | weiyonghua&#39;s Blog | YOUR_SUBTITLE</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    
    <meta name="theme-color" content="#3F51B5">
    
    
    <meta name="keywords" content="springclould">
    <meta name="description" content="2.1.6 Consul 的高可用Consul Cluster集群架构图如下：                                                                                              Consul              这边准备了三台CentOS 7的虚拟机，主机规划如下，供参考：    主机名称 IP 作用 是">
<meta name="keywords" content="springclould">
<meta property="og:type" content="article">
<meta property="og:title" content="2.1.6 Consul高可用">
<meta property="og:url" content="weiyonghua's Blog/2017/07/03/2-1-6-Consul高可用/index.html">
<meta property="og:site_name" content="weiyonghua&#39;s Blog">
<meta property="og:description" content="2.1.6 Consul 的高可用Consul Cluster集群架构图如下：                                                                                              Consul              这边准备了三台CentOS 7的虚拟机，主机规划如下，供参考：    主机名称 IP 作用 是">
<meta property="og:image" content="weiyonghua%27s%20Blog/2017/07/03/2-1-6-Consul高可用/images/consul-3.png">
<meta property="og:image" content="weiyonghua%27s%20Blog/2017/07/03/2-1-6-Consul高可用/images/consul-2.png">
<meta property="og:updated_time" content="2017-07-03T08:32:32.181Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="2.1.6 Consul高可用">
<meta name="twitter:description" content="2.1.6 Consul 的高可用Consul Cluster集群架构图如下：                                                                                              Consul              这边准备了三台CentOS 7的虚拟机，主机规划如下，供参考：    主机名称 IP 作用 是">
<meta name="twitter:image" content="weiyonghua%27s%20Blog/2017/07/03/2-1-6-Consul高可用/images/consul-3.png">
    
        <link rel="alternative" href="/atom.xml" title="weiyonghua&#39;s Blog" type="application/atom+xml">
    
    <link rel="shortcut icon" href="/favicon.ico">
    <link rel="stylesheet" href="/css/style.css?v=1.4.9">
    <script>window.lazyScripts=[]</script>
</head>

<body>
    <div id="loading" class="active"></div>

    <aside id="menu" class="hide" >
  <div class="inner flex-row-vertical">
    <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menu-off">
        <i class="icon icon-lg icon-close"></i>
    </a>
    <div class="brand-wrap">
      <div class="brand">
        <a href="/" class="avatar waves-effect waves-circle waves-light">
          <img src="/img/avatar.jpg">
        </a>
        <hgroup class="introduce">
          <h5 class="nickname">weiyonghua</h5>
          <a href="mailto:weiyonghua16@gmail.com" title="weiyonghua16@gmail.com" class="mail">weiyonghua16@gmail.com</a>
        </hgroup>
      </div>
    </div>
    <div class="scroll-wrap flex-col">
      <ul class="nav">
        
            <li class="waves-block waves-effect">
              <a href="/"  >
                <i class="icon icon-lg icon-home"></i>
                主页
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/archives"  >
                <i class="icon icon-lg icon-archives"></i>
                Archives
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/tags"  >
                <i class="icon icon-lg icon-tags"></i>
                Tags
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/categories"  >
                <i class="icon icon-lg icon-th-list"></i>
                Categories
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://github.com/1135831485" target="_blank" >
                <i class="icon icon-lg icon-github"></i>
                Github
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="http://t.qq.com/fy1135831485" target="_blank" >
                <i class="icon icon-lg icon-weibo"></i>
                Weibo
              </a>
            </li>
        
      </ul>
    </div>
  </div>
</aside>

    <main id="main">
        <header class="top-header" id="header">
    <div class="flex-row">
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light on" id="menu-toggle">
          <i class="icon icon-lg icon-navicon"></i>
        </a>
        <div class="flex-col header-title ellipsis">2.1.6 Consul高可用</div>
        
        <div class="search-wrap" id="search-wrap">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="back">
                <i class="icon icon-lg icon-chevron-left"></i>
            </a>
            <input type="text" id="key" class="search-input" autocomplete="off" placeholder="输入感兴趣的关键字">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="search">
                <i class="icon icon-lg icon-search"></i>
            </a>
        </div>
        
        
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menuShare">
            <i class="icon icon-lg icon-share-alt"></i>
        </a>
        
    </div>
</header>
<header class="content-header post-header">

    <div class="container fade-scale">
        <h1 class="title">2.1.6 Consul高可用</h1>
        <h5 class="subtitle">
            
                <time datetime="2017-07-03T08:20:00.000Z" itemprop="datePublished" class="page-time">
  2017-07-03
</time>


	<ul class="article-category-list"><li class="article-category-list-item"><a class="article-category-list-link" href="/categories/springclould专栏/">springclould专栏</a></li></ul>

            
        </h5>
    </div>

    

</header>


<div class="container body-wrap">
    
    <aside class="post-widget">
        <nav class="post-toc-wrap" id="post-toc">
            <h4>TOC</h4>
            <ol class="post-toc"><li class="post-toc-item post-toc-level-1"><a class="post-toc-link" href="#2-1-6-Consul-的高可用"><span class="post-toc-number">1.</span> <span class="post-toc-text">2.1.6 Consul 的高可用</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#搭建步骤："><span class="post-toc-number">1.1.</span> <span class="post-toc-text">搭建步骤：</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#访问集群"><span class="post-toc-number">1.2.</span> <span class="post-toc-text">访问集群</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#参考文档："><span class="post-toc-number">1.3.</span> <span class="post-toc-text">参考文档：</span></a></li></ol></li></ol>
        </nav>
    </aside>
    
<article id="post-2-1-6-Consul高可用"
  class="post-article article-type-post fade" itemprop="blogPost">

    <div class="post-card">
        <h1 class="post-card-title">2.1.6 Consul高可用</h1>
        <div class="post-meta">
            <time class="post-time" title="2017年07月03日 16:20" datetime="2017-07-03T08:20:00.000Z"  itemprop="datePublished">2017-07-03</time>

            
	<ul class="article-category-list"><li class="article-category-list-item"><a class="article-category-list-link" href="/categories/springclould专栏/">springclould专栏</a></li></ul>



            
<span id="busuanzi_container_page_pv" title="文章总阅读量" style='display:none'>
    <i class="icon icon-eye icon-pr"></i><span id="busuanzi_value_page_pv"></span>
</span>


            

        </div>
        <div class="post-content" id="post-content" itemprop="postContent">
            <h1 id="2-1-6-Consul-的高可用"><a href="#2-1-6-Consul-的高可用" class="headerlink" title="2.1.6 Consul 的高可用"></a>2.1.6 Consul 的高可用</h1><p>Consul Cluster集群架构图如下：</p>
<figure class="image-bubble">
                <div class="img-lightbox">
                    <div class="overlay"></div>
                    <img src="images/consul-3.png" alt="Consul" title="">
                </div>
                <div class="image-caption">Consul</div>
            </figure>
<p>这边准备了三台CentOS 7的虚拟机，主机规划如下，供参考：</p>
<table>
<thead>
<tr>
<th>主机名称</th>
<th>IP</th>
<th>作用</th>
<th>是否允许远程访问</th>
</tr>
</thead>
<tbody>
<tr>
<td>node0</td>
<td>192.168.11.143</td>
<td>consul server</td>
<td>是</td>
</tr>
<tr>
<td>node1</td>
<td>192.168.11.144</td>
<td>consul client</td>
<td>否</td>
</tr>
<tr>
<td>node2</td>
<td>192.168.11.145</td>
<td>consul client</td>
<td>是</td>
</tr>
</tbody>
</table>
<h2 id="搭建步骤："><a href="#搭建步骤：" class="headerlink" title="搭建步骤："></a>搭建步骤：</h2><ul>
<li>启动node0机器上的Consul（node0机器上执行）：</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">consul agent -data-dir /tmp/node0 -node=node0 -bind=192.168.11.143 -datacenter=dc1 -ui -client=192.168.11.143 -server -bootstrap-expect 1</div></pre></td></tr></table></figure>
<ul>
<li>启动node1机器上的Consul（node1机器上执行）：</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">consul agent -data-dir /tmp/node1 -node=node1 -bind=192.168.11.144 -datacenter=dc1 -ui</div></pre></td></tr></table></figure>
<ul>
<li>启动node2机器上的Consul（node2机器上执行）：</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">consul agent -data-dir /tmp/node2 -node=node2 -bind=192.168.11.145 -datacenter=dc1 -ui -client=192.168.11.145</div></pre></td></tr></table></figure>
<ul>
<li>将node1节点加入到node0上（node1机器上执行）：</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">consul join 192.168.11.143</div></pre></td></tr></table></figure>
<ul>
<li>将node2节点加入到node0上（node2机器上执行）：</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">consul join -rpc-addr=192.168.11.145:8400  192.168.11.143</div></pre></td></tr></table></figure>
<ul>
<li>这样一个简单的Consul集群就搭建完成了，在node1上查看当前集群节点：</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">consul members -rpc-addr=192.168.11.143:8400</div></pre></td></tr></table></figure>
<p>结果如下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">Node   Address              Status  Type    Build  Protocol  DC</div><div class="line">node0  192.168.11.143:8301  alive   server  0.7.0  2         dc1</div><div class="line">node1  192.168.11.144:8301  alive   client  0.7.0  2         dc1</div><div class="line">node2  192.168.11.145:8301  alive   client  0.7.0  2         dc1</div></pre></td></tr></table></figure>
<p>说明集群已经搭建成功了。</p>
<p>我们分析一下，为什么第5步和第6步需要加<code>-rpc-addr</code> 选项，而第4步不需要加任何选项呢？原因是<code>-client</code> 指定了客户端接口的绑定地址，包括：HTTP、DNS、RPC，而<code>consul join</code> 、<code>consul members</code> 都是通过RPC与Consul交互的。</p>
<h2 id="访问集群"><a href="#访问集群" class="headerlink" title="访问集群"></a>访问集群</h2><p>如上，我们三个节点都加了<code>-ui</code> 参数启动了内建的界面。我们可以通过：<code>http://192.168.11.143:8500/ui/</code> 或者<code>http://192.168.11.145:8500/ui/</code>进行访问，也可以在node1机器上通过<code>http://127.0.0.1:8500/ui/</code> 进行访问，原因是node1没有开启远程访问 ，三种访问方式结果是一致的，如下：</p>
<figure class="image-bubble">
                <div class="img-lightbox">
                    <div class="overlay"></div>
                    <img src="images/consul-2.png" alt="consul" title="">
                </div>
                <div class="image-caption">consul</div>
            </figure>
<h2 id="参考文档："><a href="#参考文档：" class="headerlink" title="参考文档："></a>参考文档：</h2><blockquote>
<p> Consul官方文档：<a href="https://www.consul.io/intro/getting-started/install.html" target="_blank" rel="external">https://www.consul.io/intro/getting-started/install.html</a></p>
<p> Consul 系列博文：<a href="http://www.cnblogs.com/java-zhao/archive/2016/04/13/5387105.html" target="_blank" rel="external">http://www.cnblogs.com/java-zhao/archive/2016/04/13/5387105.html</a></p>
<p> 使用consul实现分布式服务注册和发现：<a href="http://www.tuicool.com/articles/M3QFven" target="_blank" rel="external">http://www.tuicool.com/articles/M3QFven</a></p>
</blockquote>

        </div>

        <blockquote class="post-copyright">
    <div class="content">
        
<span class="post-time">
    最后更新时间：<time datetime="2017-07-03T08:32:32.181Z" itemprop="dateUpdated">2017年7月3日 16:32</time>
</span><br>


        这里写留言或版权声明：<a href="/2017/07/03/2-1-6-Consul高可用/" target="_blank" rel="external">weiyonghua&#39;s Blog/2017/07/03/2-1-6-Consul高可用/</a>
    </div>
    <footer>
        <a href="weiyonghua's Blog">
            <img src="/img/avatar.jpg" alt="weiyonghua">
            weiyonghua
        </a>
    </footer>
</blockquote>

        
<div class="page-reward">
    <a id="rewardBtn" href="javascript:;" class="page-reward-btn waves-effect waves-circle waves-light">赏</a>
</div>



        <div class="post-footer">
            
	<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/springclould/">springclould</a></li></ul>


            
<div class="page-share-wrap">
    

<div class="page-share" id="pageShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=weiyonghua's Blog/2017/07/03/2-1-6-Consul高可用/&title=《2.1.6 Consul高可用》 — weiyonghua's Blog&pic=weiyonghua's Blog/img/avatar.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=weiyonghua's Blog/2017/07/03/2-1-6-Consul高可用/&title=《2.1.6 Consul高可用》 — weiyonghua's Blog&source=YOUR_DESC" data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=weiyonghua's Blog/2017/07/03/2-1-6-Consul高可用/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《2.1.6 Consul高可用》 — weiyonghua's Blog&url=weiyonghua's Blog/2017/07/03/2-1-6-Consul高可用/&via=weiyonghua's Blog" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=weiyonghua's Blog/2017/07/03/2-1-6-Consul高可用/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>



    <a href="javascript:;" id="shareFab" class="page-share-fab waves-effect waves-circle">
        <i class="icon icon-share-alt icon-lg"></i>
    </a>
</div>



        </div>
    </div>

    
<nav class="post-nav flex-row flex-justify-between">
  
    <div class="waves-block waves-effect prev">
      <a href="/2017/07/03/2-2-服务提供者/" id="post-prev" class="post-nav-link">
        <div class="tips"><i class="icon icon-angle-left icon-lg icon-pr"></i> Prev</div>
        <h4 class="title">2.2 服务提供者</h4>
      </a>
    </div>
  

  
    <div class="waves-block waves-effect next">
      <a href="/2017/07/03/2-1-5-Consul常用命令/" id="post-next" class="post-nav-link">
        <div class="tips">Next <i class="icon icon-angle-right icon-lg icon-pl"></i></div>
        <h4 class="title">2.1.5 Consul常用命令</h4>
      </a>
    </div>
  
</nav>



    

<div class="comments" id="comments">
    <div class="ds-thread" data-thread-key="2-1-6-Consul高可用" data-title="2.1.6 Consul高可用" data-url="weiyonghua's Blog/2017/07/03/2-1-6-Consul高可用/"></div>
</div>
<script>
lazyScripts.push('//cdn.bootcss.com/marked/0.3.6/marked.min.js');

var duoshuoQuery = {short_name:'ysblog', theme: 'none'};
lazyScripts.push('/js/embed.min.js?v=1.4.9');


</script>







</article>

<div id="reward" class="page-modal reward-lay">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <h3 class="reward-title">
        <i class="icon icon-quote-left"></i>
        谢谢大爷~
        <i class="icon icon-quote-right"></i>
    </h3>
    <ul class="reward-items">
        
        <li>
            <img src="/img/wechat.jpg" title="微信打赏二维码" alt="微信打赏二维码">
            <p>微信</p>
        </li>
        

        
        <li>
            <img src="/img/alipay.jpg" title="支付宝打赏二维码" alt="支付宝打赏二维码">
            <p>支付宝</p>
        </li>
        
    </ul>
</div>



</div>

        <footer class="footer">
    <div class="top">
        
<p>
    <span id="busuanzi_container_site_uv" style='display:none'>
        站点总访客数：<span id="busuanzi_value_site_uv"></span>
    </span>
    <span id="busuanzi_container_site_pv" style='display:none'>
        站点总访问量：<span id="busuanzi_value_site_pv"></span>
    </span>
</p>


        <p>
            <span><a href="/atom.xml" target="_blank" class="rss" title="rss"><i class="icon icon-lg icon-rss"></i></a></span>
            <span>博客内容遵循 <a href="http://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">知识共享 署名 - 非商业性 - 相同方式共享 4.0协议</a></span>
        </p>
    </div>
    <div class="bottom">
        <p>
            <span>Power by <a href="http://hexo.io/" target="_blank">Hexo</a> Theme <a href="https://github.com/yscoder/hexo-theme-indigo" target="_blank">indigo</a></span>
            <span>weiyonghua's Blog &copy; 2015 - 2017</span>
        </p>
    </div>
</footer>

    </main>
    <div class="mask" id="mask"></div>
<a href="javascript:;" id="gotop" class="waves-effect waves-circle waves-light"><span class="icon icon-lg icon-chevron-up"></span></a>



<div class="global-share" id="globalShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=weiyonghua's Blog/2017/07/03/2-1-6-Consul高可用/&title=《2.1.6 Consul高可用》 — weiyonghua's Blog&pic=weiyonghua's Blog/img/avatar.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=weiyonghua's Blog/2017/07/03/2-1-6-Consul高可用/&title=《2.1.6 Consul高可用》 — weiyonghua's Blog&source=YOUR_DESC" data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=weiyonghua's Blog/2017/07/03/2-1-6-Consul高可用/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《2.1.6 Consul高可用》 — weiyonghua's Blog&url=weiyonghua's Blog/2017/07/03/2-1-6-Consul高可用/&via=weiyonghua's Blog" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=weiyonghua's Blog/2017/07/03/2-1-6-Consul高可用/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>


<div class="page-modal wx-share" id="wxShare">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <p>扫一扫，分享到微信</p>
    <img src="" alt="微信分享二维码">
</div>




    <script src="//cdn.bootcss.com/node-waves/0.7.4/waves.min.js"></script>
<script>
var BLOG = { ROOT: '/', SHARE: true, REWARD: true };



</script>

<script src="/js/main.min.js?v=1.4.9"></script>


<div class="search-panel" id="search-panel">
    <ul class="search-result" id="search-result"></ul>
</div>
<template id="search-tpl">
<li class="item">
    <a href="{path}" class="waves-block waves-effect">
        <div class="title ellipsis" title="{title}">{title}</div>
        <div class="flex-row flex-middle">
            <div class="tags ellipsis">
                {tags}
            </div>
            <time class="flex-col time">{date}</time>
        </div>
    </a>
</li>
</template>

<script src="/js/search.min.js?v=1.4.9" async></script>






<script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>


</body>
</html>
